﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PayBLL;
using PayEntity;

namespace Pay
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F2)
            {
                textBox1.Focus();
            }
        }

        private PayBLL.Class1 c = new PayBLL.Class1();

        private List<Class2> buyList = new List<Class2>();

        private void button1_Click(object sender, EventArgs e)
        {

            if (textBox1.Text != "")
            {
                List<PayEntity.Class1> list = c.GetListByCode(textBox1.Text);

                Class2 item = new Class2();
                if (list.Count == 0)
                {
                    MessageBox.Show("商品编号输入错误!");
                }
                else if (list.Count == 1)
                {
                    item.GoodsName = list[0].GoodsName;
                    item.SalePrice = list[0].SalePrice;
                    item.BuyCount = 1;
                    buyList.Add(item);
                }
                else
                {
                    SelectGoods sg = new SelectGoods();
                    sg.showDataList = list;
                    sg.ShowDialog();
                    PayEntity.Class1 c1 = sg.SelectedGoods;

                    item.GoodsName = c1.GoodsName;
                    item.SalePrice = c1.SalePrice;
                    item.BuyCount = 1;
                    buyList.Add(item);
                }
                RefreshBuyList();

                textBox1.Text = "";
            }
        }

        private void RefreshBuyList()
        {
            dataGridView1.DataSource = new BindingList<Class2>(buyList);
        }

        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (textBox1.Text != "")
                {
                    button1_Click(null, null);
                }
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            dataGridView1.AutoGenerateColumns = false;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            button2.ShowDialog();
            MessageBox.Show(button2.FileName);
        }


    }
}
